from gameServer import gameServer
from eventServer import eventServer
from collectCube import CollectCube
from vec3 import Vec3
from soundServer import sound

class Invincible(CollectCube):
    
    def __init__(self):
        CollectCube.__init__(self)
        
        self.boost = 1.50
        self.oldWalk = 0
        self.oldJump = 0
        
        self.setVar("texture", "bullet")
        
        self.setVar("timedItem", True)
        self.setVar("lifeSpan", 10)
        self.setVar("lifeBlinkTime", 1)
        
    def onPickUp(self, player):
        self.oldWalk = player.getVar("walk")
        self.oldJump = player.getVar("jump")
        
        player.setVar("collectFlag", False)
        player.setVar("walk", self.oldWalk * self.boost)
        player.setVar("jump", self.oldJump * self.boost)
        
        self.setVar("scale", Vec3(1.75, 1.75, 1.75))
        
    def onDropped(self, player):
        player.setVar("collectFlag", True)
        player.setVar("walk", self.oldWalk)
        player.setVar("jump", self.oldJump)
        
    def update(self, cmd, args):
        CollectCube.update(self, cmd, args)
        
        player = self.getVar("itemPlayer")
        if(not(player == None)):
            p = self.getVar("pos")
            playP = player.getVar("pos")
            p.x = playP.x
            p.y = playP.y
                                    
    def onCollision(self, dist, vec, side, sideType, above, toward, ignoreSurface, object):
        CollectCube.onCollision(self, dist, vec, side, sideType, above, toward, ignoreSurface, object)

        p = self.getVar("itemPlayer")
        if(not(p == None)):
            if(not(p == object)):
                if(object.hasVar("base")):
                    b = object.getVar("base")
                    if(b == 'player'):
                        fromPlayer = p.getVar("player")
                        toPlayer = object.getVar("player")
                        eventServer.pull('playerStomp',{'fromPlayer':fromPlayer,'toPlayer':toPlayer})
                        sound.play('invincible_kill')
                    elif(object.hasVar("vulnerable")):
                        if(object.getVar("vulnerable")):
                            gameServer.removeObject(object.getVar("name"))
                